package com.wenming.crashcachedemo;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;

import com.wenming.library.LogReport;
import com.wenming.library.save.imp.LogWriter;
import com.wenming.library.util.FileUtil;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.runtime.Permission;

import java.io.File;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    public static final String TAG = "MainActivity";

    @SuppressLint("WrongConstant")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AndPermission.with(this)
                .runtime()
                .permission(Permission.Group.STORAGE)
                .onGranted(permissions -> {
                    // Storage permission are allowed.
                })
                .onDenied(permissions -> {
                    // Storage permission are not allowed.
                })
                .start();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button1:
                String s = null;
                s.length();
                break;

            case R.id.crash3:
                new Thread(){
                    @Override
                    public void run() {
                        super.run();
                        String s = null;
                        s.length();
                    }
                }.start();
                break;

            case R.id.button2:
                LogWriter.writeLog(TAG, "打Log测试！！！！");
                break;

            case R.id.button3:
                FileUtil.deleteDir(new File(LogReport.getInstance().getROOT()));
                break;
            case R.id.crash2:
                int a = 0;
                int b = 10 / a;
                break;
        }
    }
}
